home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
101-125
/
scopedisk122
/
bassub
/
graphics.sub
< prev
next >
Wrap
Text File
|
1995-03-19
|
3KB
|
136 lines
'Small library of graphic functions which may be useful in Basic
'programs.
REM FNx
'converts x coordinates to pixel coordinates
DEF FNx(x)=INT((x-xmin)+dx/2)/dx)
REM FNy
'converts y coordinates to pixel coordinates
DEF FNy(y)=(Vertical.pixels-5)-INT((y-ymin)+dy/2)/dy)
REM FNmin
'finds minimum of 2 values
DEF FNmin(x,y)
IF x < y THEN
FNmin = x
ELSE
FNmin = y
END IF
END DEF
REM FNmax
'finds maximum of 2 values
DEF FNmax(x,y)
IF x > y THEN
FNmax = x
ELSE
FNmax = y
END IF
END DEF
REM AskWindow
'gets x1,y1,x2,y2 values for current window
SUB AskWindow(x1%,x2%,y1%,y2%)
rp&=WINDOW(7)
x1%=PEEKW(rp&+4)
y1%=PEEKW(rp&+6)
x2%=WINDOW(2)-x1%
y2%=WINDOW(3)-y1%
END SUB
REM frame
'draws a frame in the current window
SUB frame
CALL AskWindow( x1%, x2%, y1%, y2%)
LINE (x1%+64,y1%+1)-(x2%,y2%-10),,b
END SUB
REM axes
'draws x and y axes in current window
SUB axes
CALL AskWindow(x1%,x2%,y1%,y2%)
LINE (x1%+64,y2%-10)-(x2%,y2%-10)
LINE (x1%+64,y1%+1)-(x1%+64,y2%-10)
END SUB
REM ticks
'draws x and y axes in current window and places tick marks at x% and y%
'intervals on x and y axes, respectively
SUB ticks(x%,y%)
CALL AskWindow( x1%, x2%, y1%, y2%)
LINE (x1%+64,y2%-10)-(x2%,y2%-10)
LINE (x1%+64,y1%+1)-(x1%+64,y2%-10)
CALL mark(x1%,x2%,x%,1,y2%)
CALL mark(y1%,y2%,y%,2,x1%)
END SUB
REM mark
'used by ticks subroutine to place tick marks on axes
SUB mark(u1%,u2%,us%,c%,l%)
IF u1%=0 then EXIT SUB
FOR u% = u1% to u2% step sgn(u2%-u1%)*us%
IF c%=1 then
LINE (u%,l%-3)-(u%,l%+3)
ELSE
LINE (l%-5,u%)-(l%+5,u%)
END IF
NEXT u%
END SUB
REM Bars
'Number of colors used is equal to number of elements in array d()
' so be sure you use a screen appropriately defined
'Make bar graph of data in array d()
'd() array of data elements
' n% is number of elements in d()
SUB Bars(d(1),n%)
j%=FNmin(n%,14)-1
FOR i%=0 to j%
x%=100+i%*37
LINE (x%,150-d(i%))-STEP(10,-10),i%+1
LINE -STEP (0,d(i%)),i%+1
LINE -STEP (-10,10),i%+1
LINE -STEP (-20,-d(i%)),i%+1,bf
LINE -STEP (10,-10),i%+1
LINE -STEP (20,0),i%+1
NEXT i%
END SUB
REM PieChart
'Number of colors used is equal to number of elements in array value()
' so be sure you use a screen appropriately defined
'Draw Pie Chart of values from array value()
'value() array of data to plot
'n% number of elements in array value()
SUB PieChart(value(1),n%)
pi=3.141529
f=.3
REDIM colr(n%)
FOR i%=1 TO n%
sum=sum+value(i%)
colr(i%)=i%+3
NEXT i%
mx=WINDOW(2)/2
my=WINDOW(3)/2
w1=0
radius=mx-100
CIRCLE (mx,my+20),radius,1,pi,2*pi,f
LINE (mx-radius,my)-(mx-radius,my+20)
LINE (mx+radius,my)-(mx+radius,my+20)
LINE (mx,my)-(mx+radius,my)
FOR i%=1 TO n%
w2=w1+2*pi*value(i%)/sum
CIRCLE (mx,my),radius,1,-w1,-w2 ,f
'Color Segment
x=COS(w1+(w2-w1)/2)*radius/2
y=-f*SIN(w1+(w2-w1)/2)*radius/2
PAINT STEP(x,y),colr(i%),1
IF w2>pi THEN
'Draw Side Line
x=COS(w2)*radius
y=-f*SIN(w2)*radius
LINE (mx+x,my+y)-(mx+x,my+y+20)
'Color Side
IF w2-.1>pi THEN
x=COS(w2-.1)*radius
y=-f*SIN(w2-.1)*radius
PAINT (mx+x,my+y+18),colr(i%),1
END IF
END IF
w1=w2
NEXT i%
ERASE colr
END SUB